package com.example.springbootdeep2.configuration;

import com.example.springbootdeep2.annotation.ConditionalOnSystem;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;

import java.util.Map;

public class OnSystemCondition implements Condition{

    @Override
    public boolean matches(ConditionContext conditionContext, AnnotatedTypeMetadata annotatedTypeMetadata) {

        // 获取model annotationMetadata 的参数
        // 原参数获取注解的属性
        Map<String, Object> attributes = annotatedTypeMetadata.getAnnotationAttributes(ConditionalOnSystem.class.getName());
        System.out.println("=================system====>" + attributes.get("system"));

        return "linux".equals(attributes.get("system").toString());
    }

}
